#! /bin/bash

# Change for multinode config

NUM_WORKERS=1
NUM_GPUS_PER_WORKER=1
MP_SIZE=1

script_path=$(realpath $0)
script_dir=$(dirname $script_path)

OPTIONS_NCCL="NCCL_DEBUG=info NCCL_IB_DISABLE=0 NCCL_SOCKET_IFNAME=bond0 NCCL_IB_GID_INDEX=3 NCCL_NET_GDR_LEVEL=0"

# changed deepspeed engine.py
config_json="$script_dir/ds_config.json"
# config_json="$script_dir/ds_zero2_config.json"
HIDDEN=768
rm -r /root/data/checkpoints/debug-$HIDDEN
gpt_options=" \
       --model-parallel-size ${MP_SIZE} \
       --num-layers 12 \
       --hidden-size $HIDDEN \
       --num-attention-heads 12 \
       --seq-length 1024 \
       --max-position-embeddings 1024 \
       --save /root/data/checkpoints/debug-$HIDDEN \
       --load /root/data/checkpoints/debug-$HIDDEN \
       --train-iters 50000 \
       --resume-dataloader \
       --train-data msa \
       --lazy-loader \
       --loose-json \
       --tokenizer-type ProteinTokenizer \
       --split 949,50,1 \
       --distributed-backend nccl \
       --lr-decay-style cosine \
       --warmup .01 \
       --checkpoint-activations \
       --deepspeed-activation-checkpointing \
       --fp16 \
       --save-interval 100 \
       --presplit-sentences \
       --eval-interval 100 \
       --log-interval 10 \
"
# no loading nltk!!!

gpt_options="${gpt_options}
               --deepspeed \
               --deepspeed_config ${config_json} \
"

# ${OPTIONS_NCCL} 
run_cmd="deepspeed --num_nodes ${NUM_WORKERS} --num_gpus ${NUM_GPUS_PER_WORKER} pretrain_bert.py $@ ${gpt_options}"
echo ${run_cmd}
eval ${run_cmd}

set +x
